import http from "@/utils/request"
import {useUser} from "@/stores/user"
let user=useUser()
let userid=user.userid


export const cartAdd=(proid:string,num="1")=>{
    return http({
        url:"/cart/add",
        method:"post",
        data:{userid,proid,num}
    }) as Promise<{ code: string; message: string; data?: any }>
}



export const cartList=()=>{
    return http({
        url:"/cart/list",
        method:"post",
        data:{userid}
    }) as Promise<{ code: string; message: string; data?: any }>
}




export const cartRemoveOne=(cartid:string)=>{
    return http({
        url:"/cart/remove",
        method:"post",
        data:{cartid}
    }) as Promise<{ code: string; message: string; data?: any }>
}



export const cartSelectOne=(cartid:string,flag:boolean)=>{
    return http({
        url:"/cart/selectone",
        method:"post",
        data:{cartid,flag}
    }) as Promise<{ code: string; message: string; data?: any }>
}



export const cartSelectAll=(type:boolean)=>{
    return http({
        url:"/cart/selectall",
        method:"post",
        data:{userid,type}
    }) as Promise<{ code: string; message: string; data?: any }>
}





export const cartUpdateNum=(cartid:string,num:number)=>{
    return http({
        url:"/cart/updatenum",
        method:"post",
        data:{cartid,num}
    }) as Promise<{ code: string; message: string; data?: any }>
}